
#include <stdio.h>
#include <stdlib.h>

struct ListNode {
    int val;
    struct ListNode *next;
};

struct ListNode* removeElements(struct ListNode* head, int val) {
    struct ListNode* dummyNode = (struct ListNode*)malloc(sizeof(struct ListNode));
    dummyNode->val = val - 1;
    dummyNode->next = head;
    struct ListNode* prev = dummyNode;
    while (prev->next != NULL) {
        if (prev->next->val == val) {
            prev->next = prev->next->next;
        } else {
            prev = prev->next;
        }
    }
    return dummyNode->next;
}

int main() {
    struct ListNode* node1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* node2 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* node3 = (struct ListNode*)malloc(sizeof(struct ListNode));
    node1->val = 1;
    node1->next = node2;
    node2->val = 2;
    node2->next = node3;
    node3->val = 6;
    node3->next = NULL;

    struct ListNode* result = removeElements(node1, 6);

    while (result != NULL) {
        printf("%d -> ", result->val);
        result = result->next;
    }
    printf("NULL\n");

    return 0;
}
